home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-18 | 7.6 KB | 234 lines | [TEXT/CCL2] |
- ;;;;ADLM.lisp
- ;;;;AfterDark LISP Module written in Macintosh Common LISP.
- ;;;;This is the (non-gratuitously) largest AfterDark Module you will ever see.
- ;;;;Special thanks to all the people I bugged with idiotic ToolBox questions.
-
-
- (require :quickdraw)
-
- (defparameter *edge-cutoff* 5
- "The cutoff when a pixel is outweighed by its neighbors."
- )
- (defparameter *cedge-cutoff* (floor (* .3 *white-color*))
- "When things aren't Black&White anymore…use *edge-cutoff*."
- )
- (defparameter *debugs* nil
- "A list of keywords to test to see if I want to output some debugging stuff."
- )
-
- (defun ADLM-black (&optional (port (wptr (select-window))))
- "port
- Does not-so-funky screen-saver things to port…paints all of port black."
- (with-port port
- (with-fore-color *black-color*
- (#_FillRgn (rref port :GrafPort.visrgn) *black-pattern*)
- ) ) )
-
- (defun ADLM-black-hole (&optional (port (wptr (select-window))))
- "port
- Does funky screen-saver things to port.
- Specifically, it uses standard AI-vision edge-detection to find objects in
- the port, and then blacks-out/restores randomly selected objects."
-
- (when (member :original *debugs*)
- (make-instance 'window :wptr port :color-p *color-available*)
- )
-
- ;Get a copy of the port and/or force it into a CGrafPort
- (rlet ((c-port :CGrafPort)
- (laplace-port :CGrafPort)
- (shaper-port :CGrafPort)
- (cpix :RGBColor)
- (colorp (color-grafport-p port))
- )
- (if colorp
- (%setf-macptr c-port port)
- ;Get a B/W into a CGrafPort somehow…maybe next year. NOT!
- ;Although I can't handle B&W yet, I do exit gracefully.
- (without-interrupts
- (make-instance 'window
- :window-type :single-edge-box
- :view-position :centered
- :view-size #@(600 100)
- :view-subviews
- (list
- (make-instance 'static-text-dialog-item
- :dialog-item-text "I don't do Black and White."
- :view-font '("Geneva" 40)
- :view-position #@(50 20)
- ) ) )
- (sleep 10)
- (return-from 'ADLM-black-hole)
- )
- )
-
- (when (member :copy *debugs*)
- (make-instance 'window :port c-port :color-p *color-available*)
- )
-
- ;Get some useful size numbers.
- (let* ((pixmap (rref c-port :CGrafPort.PixMap))
- (bail (unless (handlep pixmap) (return-from ADLM-black-hole)))
- (left (rref pixmap :PixMap.Bounds.left))
- (top (rref pixmap :PixMap.Bounds.top))
- (right (rref pixmap :PixMap.Bounds.right))
- (bottom (rref pixmap :PixMap.Bounds.bottom))
- (width (- right left))
- (height (- bottom top))
- (laplace (rref laplace-port :CGrafPort.PixMap))
- (bail (unless (handlep laplace (return-from ADLM-black-hole))))
- (shaper (rref shaper-port :CGrafPort.PixMap))
- (bail (unless (handlep shaper (return-from ADLM-black-hole))))
- (l-bounds (rref laplace :PixMap.Bounds))
- (s-bounds (rref shaper :PixMap.Bounds))
- (shapes nil)
- )
- (declare (ignore bail))
-
- (unwind-protect
-
- ;Protected form
- (progn
-
- ;Compute LaPlacian transformation from c-port to laplace
-
- (with-focused-view laplace-port
- ;Forshadowing…
- ;By definition, the edge of the PixMap is… well… the edge.
- (dotimes (h width)
- (#_SetCPixel h 0 *black-rgb*)
- (#_SetCPixel h height *black-rgb*)
- )
- (dotimes (v height)
- (#_SetCPixel 0 v *black-rgb*)
- (#_SetCPixel 0 width *black-rgb*)
- )
- (dotimes (h (- width 2))
- (dotimes (v (- height 2))
- (#_SetCPixel (1+ h) (1+ v)
- (color-to-rgb
- (with-focused-view c-port
- (- (* 8 (get-c-color (1+ h) (1+ v) rgb))
- (get-c-color h v rgb)
- (get-c-color (1+ h) v rgb)
- (get-c-color (+ h 2) v rgb)
- (get-c-color h (1+ v) rgb)
- ;I think I re-typed this section 8 times.
- ;And each time, I tried to put in (1+ h) (1+ v)
- ;This, of course, is the pixel I *DON'T* want.
- ;I want all its neighbors.
- (get-c-color h (+ v 2) rgb)
- (get-c-color (1+ h) (+ v 2) rgb)
- (get-c-color (+ h 2) (+ v 2) rgb)
- ) ) ) ) ) )
-
- (when (member :laplace *debugs*)
- (make-instance 'window :port laplace-port :color-p *color-available*)
- )
-
- ;And now we map all these numbers to 0 or 1.
- ;For readability, I would have another CGrafPort, edges-port, and
- ;its pixmap, but then I'd have to swap ports even more than I
- ;already have.
- (if colorp
- (dotimes (h width)
- (dotimes (v height)
- (if (< (get-c-color h v rgb) *cedge-cutoff*)
- (#_SetCPixel h v *white-rgb*)
- (#_SetCPixel h v *black-rgb*)
- ) ) )
- ;Now, of course, I know we can't get here, but the only
- ;difference from the code above is *edge-cutoff* instead of
- ;*cedge-cutoff*, so I guess I'll make it easy on myself for the
- :vaporware upgrade and copy and paste in the code.
- ;Aren't I the go-getter?
- (dotimes (h width)
- (dotimes (v height)
- (if (< (get-c-color h v rgb) *edge-cutoff*)
- (#_SetCPixel h v *white-rgb*)
- (#_SetCPixel h v *black-rgb*)
- ) ) )
- )
-
- (when (member :edges *debugs*)
- (make-instance 'window :port laplace-port :color-p *color-available*)
- )
-
- (dotimes (h width)
- (dotimes (v height)
- (#_SeedCFill laplace shaper l-bounds s-bounds h v
-
- ) )
-
-
-
-
- ;Cleanup forms. This code WILL execute, if a LISP error is generated
- ;within the protected form (starts with progn) above.
- (#_DisposeHandle laplace)
- (#_DisposeHandle edges)
- (#_DiseposeHandle shaper)
- )
- ) ) )
-
- ;;;;A short function to shorten my typing.
- (defun get-c-color (h v rgb-ptr)
- "h v rgb-ptr
- Calls _GetCPixel and then rgb-to-color.
- rgb-ptr will be remain modified."
- (#_GetCPixel h v rgb-ptr)
- (rgb-to-color rgb-ptr)
- )
-
-
- ;;;;An array window takes a LISP array and draws it as a BitMap/PixMap.
- (defclass array-window (window)
- ((array
- :documentation "An array to display."
- :accessor array
- :initarg :array
- :initform #()
- :type 'array
- )
- )
- (:default-initargs
- :color-p *color-available*
- ) )
-
- (defmethod initialize-instance :after ((view array-window) &key (array #() array-supplied-p))
- (when array-supplied-p
- (apply #'set-view-size view (array-dimensions array))
- ) )
-
- (defmethod view-draw-contents :after ((view array-window))
- (let* ((array (array view))
- (dims (array-dimensions array))
- (width (car dims))
- (height (cadr dims))
- )
- (dotimes (h width)
- (dotimes (v height)
- (#_ForeColor (aref array h v))
- (#_MoveTo h v)
- (#_LineTo h v)
- ) ) ) )
-
-
- (defun select-window ()
- "Allows the user to select any visible window."
- (car (select-item-from-list (windows)))
- )
-
- (defun color-grafport-p (port)
- "port
- Returns T iff port is a CGrafPort."
- #|
- (let* ((pixmap (rref port :CGrafPort.PortPixMap))
- (rowbytes (rref pixmap :PixMap.RowBytes))
- )
- (zerop (logand rowbytes #b0000000000000001))
- )
- |#
- (declare (ignore port))
- t
- )